package com.github.sort;

public class ShellSort{
    private ShellSort(){}
    public static void shellsort(Comparable[] R){
        int N=R.length;
        int h=1;
        while (h<N/3)h=3*h+1;
        while (h>=1){
            for (int i = h; i < N; i++) {
                for (int j = i; j >=h&&less(R[j],R[j-h]); j-=h) {
                    Comparable temp=R[j-h];
                    R[j-h]=R[j];
                    R[j]=temp;
                }
            }
            h=h/3;
        }
    }
    private static boolean less(Comparable v,Comparable w){
        return v.compareTo(w)<0;
    }
}
